﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace SceneControl
{
    static class SceneManager
    {
        static public Scene cena = null;
        static private CENA cenaAtual;
        static KeyboardState teclado = new KeyboardState();
        static string textScene;
        static SpriteFont arial;
        static public ContentManager content;

        public enum CENA
        {
            CENA_ABERTURA,
            CENA_GAMEOVER,
            CENA_LEVEL,
        }

        public static void LoadImages(ContentManager content)
        {
            cena.LoadImages(content);
            SceneManager.content = content;
            arial = content.Load<SpriteFont>("Arial");
        }

        public static void Update(GameTime gameTime)
        {
            teclado = Keyboard.GetState();

            if (teclado.IsKeyDown(Keys.D1))
            {
                    SceneManager.TrocarCena(0);
                    SceneManager.LoadImages(content);
                    SceneManager.textScene = "Level's Scene";
            }
            if (teclado.IsKeyDown(Keys.D2))
            {
                    SceneManager.TrocarCena(2);
                    SceneManager.LoadImages(content);
                    SceneManager.textScene = "Opening's Scene";
            }
            if (teclado.IsKeyDown(Keys.D3))
            {
                    SceneManager.TrocarCena(1);
                    SceneManager.LoadImages(content);
                    SceneManager.textScene = "GameOver's Scene";
            }
            
            cena.Update(gameTime);
        }
        public static void Draw(SpriteBatch spriteBatch)
        {
            cena.Draw(spriteBatch);
            spriteBatch.DrawString(arial, textScene, new Vector2(200, 200), Color.White);
            spriteBatch.DrawString(arial, "Press 1, 2 or 3 to Change Scene", new Vector2(200, 100), Color.White);
        }

        static public void TrocarCena(int cena)
        {
            switch (cena)
            {
                case 0:
                    {
                        SceneManager.cena = new Level();
                        cenaAtual = CENA.CENA_LEVEL;
                        break;
                    }
                case 1:
                    {
                        SceneManager.cena = new GameOver();
                        cenaAtual = CENA.CENA_GAMEOVER;
                        break;
                    }
                case 2:
                    {
                        SceneManager.cena = new Opening();
                        cenaAtual = CENA.CENA_ABERTURA;
                        break;
                    }
            }
        }
        static public void Setup()
        {
            textScene = "Opening's Scene";
            SceneManager.cena = new Opening();
            cenaAtual = CENA.CENA_ABERTURA;
            
        }
    }
}
